<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			#diva{
				width: 500px;
				height: 500px;
				background-color: #00FFFF;
			}
			#divb{
				width: 400px;
				height: 400px;
				background-color: #1E90FF;
				margin:25px 0 0 50px;
			}
			#divc{
				width: 300px;
				height: 300px;
				background-color: #FF7F50;
				margin:25px 0 0 50px;
			}
			#divd{
				width: 200px;
				height: 200px;
				background-color: chartreuse;
				margin:25px 0 0 50px;
			}
		</style>
	</head>
	<body>
	<!-- 	
		      4.通过最底层DIV，打印每层父DIV，如：
				1级父元素为（），1级父节点为（）
				2级父元素为（），2级父节点为（）
				....
		      5.查找每个DIV的子元素和子对象 -->
		<div id="diva">
			文字啊啊啊啊啊啊啊啊啊啊啊啊啊啊
			<div id="divb">
				<p>P标签</p>
				<div id="divc">
					<a href="htpps://www.baidu.com">百度一下</a>
					<div id="divd">
						<img src="css/01.jpg" width="144px" height="90px">
					</div>
				</div>
			</div>
		</div>
		<button type="button" onclick="gain();">获取父DIV</button>
		<button type="button" onclick="chren();">获取子DIV</button>
	</body>
	<script type="text/javascript">
		function gain(){
			console.log('1级父元素为:');
			console.log(divd.parentElement)
			console.log('1级父节点为:');
			console.log(divd.parentNode)
			console.log('2级父元素为:');
			console.log(divd.parentElement.parentElement)
			console.log('2级父节点为:');
			console.log(divd.parentNode.parentNode)
			console.log('3级父元素为:');
			console.log(divd.parentElement.parentElement.parentElement)
			console.log('3级父节点为:');
			console.log(divd.parentNode.parentNode.parentNode)
			console.log('4级父元素为:');
			console.log(divd.parentElement.parentElement.parentElement.parentElement)
			console.log('4级父节点为:');
			console.log(divd.parentNode.parentNode.parentNode.parentNode)
			console.log('5级父元素为:');
			console.log(divd.parentElement.parentElement.parentElement.parentElement.parentElement)
			console.log('5级父节点为:');
			console.log(divd.parentNode.parentNode.parentNode.parentNode.parentNode)
			console.log('6级父元素为:');
			console.log(divd.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement)
			console.log('6级父节点为:');
			console.log(divd.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode)
		}
		function chren(){
			console.log('查找div的子元素')
			console.log(diva.children);
			console.log('查找div的子对象')
			console.log(diva.childNodes);
		}
	</script>
</html>
